extension NumExtension on num {
  ///格式化0
  String formatZero() {
    num i = this;
    return (i >= 10) ? i.toString() : "0$i";
  }

  ///秒转00:00
  String formatTime() {
    num seconds = this;
    int minute = seconds ~/ 60;
    num second = seconds % 60;
    return '${minute < 10 ? '0$minute' : minute}:${second < 10 ? '0$second' : second}';
  }

  ///数字转成Int
  num2int() {
    num number = this;
    try {
      if (number is String) {
        return int.parse(number as String);
      } else if (number is int) {
        return number;
      } else if (number is double) {
        return number.toInt();
      } else {
        return 0;
      }
    } catch (e) {
      return 0;
    }
  }

  ///数字转成double
  num2double() {
    num number = this;
    try {
      if (number is String) {
        return double.parse(number as String);
      } else if (number is int) {
        return number.toDouble();
      } else if (number is double) {
        return number;
      } else {
        return 0.0;
      }
    } catch (e) {
      return 0.0;
    }
  }
}
